from django.shortcuts import render
from rest_framework.generics import ListAPIView
from .models import CourseCategory,Course
from .serializers import CourseCategoryModelSerializer,CourseModelSerializer
# Create your views here.
class CourseCategoryListAPIView(ListAPIView):
    """课程分类列表"""
    queryset = CourseCategory.objects.filter(is_show=True,is_delete=False).order_by("orders")
    serializer_class = CourseCategoryModelSerializer



from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import OrderingFilter
from .paginations import CustomPageNumberPagination
class CourseListAPIView(ListAPIView):
    """课程列表"""
    queryset = Course.objects.filter(is_show=True,is_delete=False).order_by("orders")

    serializer_class = CourseModelSerializer
    filter_backends = [DjangoFilterBackend,OrderingFilter]
    # 设置支持设置的筛选过滤字段
    filter_fields = ('course_category',)
    # 设置支持设置的排序字段
    ordering_fields = ('id','students','price')
    #指定分页器
    pagination_class = CustomPageNumberPagination

from .serializers import CourseDetailModelSerializer
from rest_framework.generics import RetrieveAPIView
class CourseRetrieveAPIView(RetrieveAPIView):
    queryset = Course.objects.filter(is_show=True,is_delete=False)
    serializer_class = CourseDetailModelSerializer

